<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="关键词：">
          <el-input v-model="listPram.keyword" placeholder="用户名称|手机号" clearable class="vsWidth"/>
        </el-form-item>
        <el-form-item label="选择时间：">
          <el-date-picker
              v-model="value1"
              @change="handleChange"
              value-format="yyyy-MM-dd" format="yyyy-MM-dd"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 220px"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="地区：" prop="areaId">
          <el-cascader class="col"
                       placeholder="可输入地区名称进行搜索"
                       v-model="value"
                       :options="options"
                       clearable
                       :props="{ expandTrigger: 'hover' }"
                       filterable
                       @change="handleChange1"></el-cascader>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
        <el-form-item style="margin-left:100px;">
          {{  this.dataStatistics }}
        </el-form-item>
      </el-form>
      <el-table :data="listData.list" size="mini" :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column label="ID" prop="id" width="120" ></el-table-column>
        <el-table-column label="用户名称" prop="name" width="150"/>
        <el-table-column label="所在地区" prop="areaText" width="180"/>
        <el-table-column label="手机号" prop="phone" width="150"/>
        <el-table-column label="流水号" prop="orderId" min-width="150"/>
        <el-table-column label="金额" prop="price" min-width="80"/>
        <el-table-column label="创建时间" prop="createTime" min-width="100"/>
<!--        <el-table-column label="操作" min-width="180" fixed="right" align="center">-->
<!--          <template slot-scope="scope">-->
<!--&lt;!&ndash;            <el-button icon="el-icon-edit" size="mini" type="primary" @click="openEdit(scope.row.id)"  v-has-permi="['admin:vip:detail']">详情</el-button>&ndash;&gt;-->
<!--            <el-button icon="el-icon-delete" size="mini" type="danger" @click="handlerDelete(scope.row.id)"  v-has-permi="['admin:vip:delete']">删除</el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <el-pagination
        :current-page="listPram.page"
        :page-sizes="[20,40,60,80,100]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="listData.count"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
      :visible.sync="editDialog.show"
      :title="editDialog.id? '编辑':'新增'"
      destroy-on-close
      :close-on-click-modal="false"
      width="1200px">
      <edit
        v-if="editDialog.show"
        :id="editDialog.id"
        @hideEditDialog="hideEditDialog"
        ref="editForm"
      />
    </el-dialog>
  </div>
</template>

<script>
import edit from './edit.vue'
import {deleteRow, updateStatus, vipList} from "@/api/vip";
import {checkPermi} from "@/utils/permission";
import { optionsList, vipNews} from "@/api/business";
export default {
  components: { edit },
  data() {
    return {
      listData: { list: [],count:0 },
      listPram: {
        keyword: '',
        startTime: '',
        areaId:'',
        endTime: '',
        page: 1,
        limit: 20,
      },
      value1:'',
      editDialog:{
        show:false,
        id:null
      },
      tableLoading:false,
      value: [],
      options: [{
        value: '',
        label: '',
        children: [{
          value: '',
          label: '',
          children: [{
            value: '',
            label: ''
          }]
        }]
      }],
      dataStatistics:''
    }
  },
  mounted() {
    this.getList()
    this.getOptions()
    this.getDataStatistics()
  },
  created() {
    if(this.$route.query.keyword)
    {
      this.listPram.keyword=this.$route.query.keyword
    }
  },
  methods: {
    getDataStatistics(){
      vipNews().then(res => {
        this.dataStatistics = res.data
      })
    },

    handleChange1(value) {
      this.listPram.areaId = value[2]
    },
    getOptions() {
      optionsList().then(res => {
        this.options = res
      })
    },
    handleChange(value) {
      if (Array.isArray(value) && value.length === 2) {
        this.listPram.startTime = value[0];
        this.listPram.endTime = value[1];
      }
    },
    checkPermi,
    getList(){
      this.tableLoading=true
      vipList(this.listPram).then(res=>{
        this.listData=res;
      }).finally(()=>{})
      this.tableLoading=false;
    },
    openEdit(id=null){
      this.editDialog.id=id;
      this.editDialog.show=true
    },
    handlerDelete(id) {
      this.$confirm('确认删除该数据吗？').then(() => {
        const loading=this.$loading({text:'删除中',background:'rgba(255,255,255,.5)'})
        deleteRow(id).then(() => {
          this.$message.success('删除成功')
          this.getList()
        }).finally(()=>{
          loading.close()
        })
      })
    },
    hideEditDialog() {
      this.editDialog.show = false
      this.getList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    handleStatusChange(status,id){
      const loading=this.$loading({text:'更新中',background:'rgba(255,255,255,.5)'})
      updateStatus(id,status).then(()=>{
        this.$message.success('更新状态成功')
        this.getList()
      }).finally(()=>{
        loading.close()
      })
    },
    resetQuery(){
      this.listPram.keyword = '';
      this.value1 = '';
      this.listPram.startTime = '';
      this.listPram.endTime = '';
      this.listPram.areaId = null;
      this.value = ''
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">
.vsWidth{
  width: 200px;
}
</style>
